﻿package jokers{
	import jokers.*;
	import jokers.JAdv.*;
	
	import flash.display.MovieClip;
	import flash.text.TextField;
	import flash.geom.Point;
	import flash.display.Stage;
	import flash.display.SimpleButton;

	//保存的全是全局信息
    public class JPara { 
		public static const POWER_LENGTH:int = 200;
		//public static var stage:Stage;
		public static var stage:MovieClip;
		
		public static var t_tips:TextField;
		public static var t_score:TextField;
		public static var t_timer:TextField;
		
		public static var m_power:MovieClip;
		public static var m_refresh:MovieClip;
		public static var m_search:MovieClip;
		
		public static var btn_search:SimpleButton;
		public static var btn_refresh:SimpleButton;
		
		public static var mc_tip:MovieClip;
		
		public static var chapters:String = "222222222222222222";
		public static var currentCpt:int = -1;
		
		public static var toolEnable:String = "0000000000";
		
		public static var jchapter:JChapter = null;
		
		public static var crystalNum:int = 8  
		
		public static var power:int = 0;
		public static var powerHas:int = 0;
		
		public static var tool_search:int = 0;
		public static var tool_refresh:int = 0;
		
		public static var score:int = 0;
		public static var timer:int = 0;
		public static var timer_total:int = 0;
		
		public static var m_combo:int = 0;
		public static var max_combo:int = 0;
		public static var long_combo:Boolean = false;
		
		public static var num_crystal:Array = new Array();
		public static var num_tool:Array = new Array();
		
		public static function initGameInfo():void{
			crystalNum = 8;
			score = 0;
			timer = 0;
			timer_total = 181;
			
			power = 0;
			powerHas = 0;
			
			tool_search = 3;
			tool_refresh = 1;
			
			m_combo = 0;
			max_combo = 0;
			
			num_crystal = new Array();
			for(var i:int = 0 ; i < 8 ; i++){
				num_crystal[i] = 0;
			}
			
			num_tool = new Array();
			for(i = 0 ; i < JTool.TOOL_NUM ; i++){
				num_tool[i] = 0;
			}
			
			/*num_tool[JTool.TOOL_REFRESH] = 1;
			num_tool[JTool.TOOL_SEARCH] = 3;
			
			m_refresh.t_num.text = num_tool[JTool.TOOL_REFRESH];
			m_search.t_num.text = num_tool[JTool.TOOL_SEARCH];*/
			
			m_refresh.t_num.text = 1;
			m_search.t_num.text = 3;
		}
		
		public static function getComboTime():int{
			if(long_combo){
				return 2500;
			}
			return 2000;
		}
		
		public static function addScore(value:Number):void{
			score += value*10;
		}
		
		public static function addPower(value:Number):void{
			power += value*4;
			while(power > POWER_LENGTH){
				powerHas++;
				power -= POWER_LENGTH;
				
				JTimer.getInstance().fouseTick();
				
				JTool.newTool();
			}
		}
		
		//添加一种颜色消除
		public static function addCrystal(ary:Array):void{
			if(ary.length != 0){
				var jd:JDelete = JDelete(ary[0]);
				var p:Point = Point(jd.points[0]);
				
				var c:MovieClip = JMatrix.getInstance().getCrystal(p.x,p.y,false);
				var type:int = JCrystal.getCrystalType(c);
				
				num_crystal[type]++;
			}
		}
		
		public static function set combo(value:int):void{
			m_combo = value;
			
			if(m_combo > max_combo) max_combo = m_combo;
		}
		
		public static function get combo():int{
			return m_combo;
		}
		
		public static function get timeUsed():int{
			return JTimer.getInstance().getTimePass();
		}
		
		public static function get stars():int{//返回1~3
			var m_star:int = jchapter.getStar();
			if(m_star != -1){
				return m_star;
			}
		
			var per:Number = JTimer.getInstance().getTimePass() / JPara.timer_total;
			if(per < 0.2){
				return 3;
			}else if(per < 0.6){
				return 2;
			}
			return 1;
		}
		
		//获取星级，如果是-1说明没有玩过，如果是0说明玩过但是没有过，玩过范围1~3
		public static function getStar(cnum:int):int{
			return Number(chapters.substr(cnum,1)) - 1;
		}
		
		//设置是否冒险过~
		public static function visited(cnum:int,star:int = 0):void{
			//trace("-->"+chapters + " - " + cnum);
			var cpt:String = "";
			for(var i:int = 0 ; i < chapters.length ; i++){
				var cc:String = chapters.substr(i,1);
				
				if(i == cnum){
					//if(cc == "0") 
					if(getStar(cnum) < star + 1){
						cc = (star + 1) + "";
					}
				}
				cpt += cc;
			}
			chapters = cpt;
			//trace("   "+chapters);
		}
		
		//是否显示关卡，before为前驱关卡，用“,”分开
		public static function showChapterBtn(mc:MovieClip,before:String):void{
			if(before == ""){
				mc.visible = true;
				return;
			}
			
			var cpts:Array = before.split(",");
			
			mc.visible = false;
			for(var i:Number = 0 ; i < cpts.length ; i++){
				var cnum:Number = Number(cpts[i]);
				
				if(chapters.substr(cnum,1) != "0" && chapters.substr(cnum,1) != "1"){
					mc.visible = true;
					return;
				}
				
				/*if(cnum > 0 && chapters.substr(cnum - 1,1) != "0"){
					mc.visible = true;
					return;
				}*/
			}
		}
	}
}